
cd "C:\Users\patri\Dropbox\My Projects\Spring 2021\Empirical IR\Data\


use "threatHR_2.dta", clear

xtset ccode year
drop if year <1960 | threat==.

by ccode:egen avg_threat = mean(threat)
by ccode:egen sd_threat = sd(threat)

gen lb = avg_threat-(1.96*sd_threat)
gen ub = avg_threat+(1.96*sd_threat)

egen order = group(avg_threat stateabb) 
order order avg_threat


labmask order , values(statenme)

sort avg_threat ccode
drop if ccode==316

set scheme plotplain

ciplot threat if oced==0, by( order ) hor sort(avg_threat) ///
ylabel(2 29 56 89 122 158 188 224 254 284 314 341 368 398 419 443 461 476,valuelabel) ///
ytitle("") xtitle("Mean External Threat, 1960 - 2016") 

use "threatHR_2.dta", clear

xtset ccode year

drop if statenme=="Republic of Vietnam"
*No longer exists in post 1980 sample

by ccode:egen avg_threat80 = mean(threat)  if year <=2001 & year >=1980
by ccode:egen sd_threat80 = sd(threat) if year <=2001 & year >=1980

gen lb80 = avg_threat80-(1.96*sd_threat80) if year <=2001 & year >=1980
gen ub80 = avg_threat80+(1.96*sd_threat80) if year <=2001 & year >=1980

by ccode:egen avg_threat01 = mean(threat) if year >2001 
by ccode:egen sd_threat01 = sd(threat) if year >2001 

by ccode:egen avg_threat01a = mean(avg_threat01) 
by ccode:egen avg_threat80a = mean(avg_threat80) 

drop avg_threat80 avg_threat01
ren  avg_threat01a avg_threat01
ren  avg_threat80 avg_threat80

gen lb01= avg_threat01-(1.96*sd_threat01) if year >2001 
gen ub01 = avg_threat01+(1.96*sd_threat01) if year >2001 

egen order = group(avg_threat80 stateabb) 


labmask order , values(statenme)



sort avg_threat80 

lab var avg_threat80 "Mean Threat 1980-2001"
lab var avg_threat01 "Mean Threat 2002-2016"


set scheme plotplain
 graph dot avg_threat80 avg_threat01 if oced==0 & avg_threat80 > 1  & ccode!=817,  over(order ) ///
 legend(label(1 "Mean Threat 1980-2001") label(2 "Mean Threat 2002-2016"))
 
